<style type="text/css">
    .hide{display: none;}
    .clear{clear: both;}
    .laydate-time-list{padding-bottom:0;overflow:hidden}
    .laydate-time-list>li{width:50%!important;}
    .laydate-time-list>li:last-child { display: none;}
    .green{color: green;}
    .blue{color: #1E9FFF;}
    .red{color: red;}
    .xian{margin: 5px 0px;height: 1px;width: 100%;clear: both;border-top: 1px dashed #c1c1c1;}
</style>
<script>
    var baseUrl = "<?php echo $baseUrl; ?>?t=1";
</script>

<div class="layui-row search-row" id="search-box">
    <div class="item">
        <div class="row" style="width: 330px">
            <div class="box">
                <span class="title">班次类型：</span>
                <div data-key="type" data-type="list" class="search-key list" >
                    <ul>
                        <li><span data-value="1">固定班次</span></li>
                        <li><span data-value="2">流水班次</span></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="row" style="width: 330px">
            <div class="box">
                <span class="title">订单状态：</span>
                <div  data-key="order_status" data-type="select" class="txt search-key" >
                    <select name="order_status" lay-filter="order_status" class="select">
                        <option value="">请选择</option>
                        <option value="0">未支付</option>
                        <option value="1">未派车</option>
                        <option value="2">已派车</option>
                        <option value="3">已发车</option>
                        <option value="4">已完成</option>
                        <option value="5">已失效</option>
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="row" style="width: 330px">
            <div class="box">
                <span class="title">变更状态：</span>
                <div  data-key="status" data-type="select" class="txt search-key" >
                    <select name="status" lay-filter="status" class="select">
                        <option value="">请选择</option>
                        <option value="0">取消</option>
                        <option value="1">未支付过期</option>
                        <option value="3">改签</option>
                        <option value="4">退款</option>
                    </select>
                </div>
            </div>
        </div>
    </div>
</div>
<div>
<?php if(Cm::$app->limitGet('/order/index','sendcar')){ ?>
    <a href="javascript:;" onclick="app.sendcar.hascheck()" class="layui-btn layui-btn-normal layui-btn-sm">派车</a>    
<?php } ?>    
<?php if(Cm::$app->limitGet('/order/add')){ ?>
    <!-- <a href="javascript:;" onclick="app.add()" class="layui-btn layui-btn-normal layui-btn-sm">新增订单</a> -->
<?php } ?>
</div>
<table data-url="<?php echo $baseUrl; ?>?action=list"
       data-search="#search-box"
       data-page=""
       data-height="full-350"
       id="data-list" 
       lay-filter='data-list' style="display: none;">
    <thead>
    <tr>
        <th width="160" align="center" field="order_number">订单号</th>
        <th width="250" field="circuit_name">线路名称</th>
        <th width="160" align="center" field="departuretime">发车时间</th>
        <th width="130" align="center" templet="#tpl-order_status">订单状态</th>
        <th width="90" align="center" field="ridership">乘客数</th>
        <th width="100" align="center" field="order_price">订单金额</th>
        <th width="160" align="center" field="addtime">创建时间</th>
        <th minWidth="200" align="center" toolbar="#tpl-cmd">操作</th>
    </tr>
    </thead>
</table>

<script type="text/html" id="tpl-order_status">
    {{# if(d.order_status==0){ }}
    <span>待支付</span>
    {{# }else if(d.order_status==1){ }}
    <span class="green">已支付未派车</span>
    {{# }else if(d.order_status==2){ }}
    <span class="green">已支付已派车</span>
    {{# }else if(d.order_status==3){ }}
    <span class="green">已发车</span>
    {{# }else if(d.order_status==4){ }}
    <span class="blue">已完成</span>
    {{# }else if(d.order_status==5){ }}
    <span class="red">
        {{# if(d.status == 0){ }}
        已取消
        {{# }else if(d.status==1){ }}
        未支付过期
        {{# }else if(d.status==2){ }}
        已删除
        {{# }else if(d.status==3){ }}
        已改签
        {{# }else if(d.status==4){ }}
        已退票
        {{# } }}
    </span>
    {{# }}}
</script>

<script type="text/html" id="tpl-pay_type">
    {{# if(d.pay_type==1){ }}
    <span>微信</span>
    {{# }else{ }}
    <span>支付宝</span>
    {{# }}}
</script>

<script type="text/html" id="tpl-cmd">
    <?php if(Cm::$app->limitGet('/order/index','info')){ ?>
        <a href="javascript:;" onclick="app.info(this,{{d.id}})" class="layui-btn layui-btn-normal layui-btn-sm">详情</a>
    <?php } ?>
    <?php if(Cm::$app->limitGet('/order/index','auditinfo')){ ?>
        {{# if(d.is_change!=0 && d.status==1 && (d.order_status==1 || d.order_status==2) ){ }}
        <a href="javascript:;" onclick="app.change.audit(this,{{d.is_change}})" class="layui-btn layui-btn-normal layui-btn-sm">改签审核</a>
        {{# } }}
    <?php } ?>
    <?php if(Cm::$app->limitGet('/order/index','changelist')){ ?>
        {{# if(d.change_list==1){ }}
        <a href="javascript:;" onclick="app.change.list(this,{{d.id}})" class="layui-btn layui-btn-normal layui-btn-sm">改签记录</a>
        {{# } }}
    <?php } ?>
    {{# if(d.status==4){ }}
    <a href="javascript:;" onclick="app.refundinfo(this,{{d.id}})" class="layui-btn layui-btn-normal layui-btn-sm">退票详情</a>
    {{# } }}
    <span style="display: none;">{{JSON.stringify(d)}}</span>
</script>
<script type="text/html" id="tpl-sendcar">
    <div class="layui-card" style="box-shadow: none;">
        <div class="layui-card-header">派车</div>
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div id="sendcar-box" style="overflow:hidden;overflow-y: auto;margin-bottom: 10px;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择线路</label>
                        <div class="layui-input-inline">
                            <select lay-filter="circuit" id="circuit">
                                <option value="">请选择</option>
                                {{each circuit as value}}
                                <option value="{{value.circuit_id}}">{{value.name}}</option>
                                {{/each}}
                            </select>  
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择班次</label>
                        <div class="layui-input-inline" id="shift-box">
                            <select lay-filter="shift" id="shift">
                                <option value="">请选择</option>
                            </select>  
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">检票员</label>
                        <div class="layui-input-inline" id="inspector-box">
                            <select lay-filter="inspector" id="inspector">
                                <option value="">请选择</option>
                            </select>  
                        </div>
                    </div> 

                    <div class="layui-form-item">
                        <label class="layui-form-label">车辆选择</label>
                        <div class="layui-input-inline" id="car-box">
                            <select lay-filter="car" id="car">
                                <option value="">请选择</option>
                            </select>  
                        </div>
                    </div>

                    <div class="layui-form-item hide passenger-box">
                        <label class="layui-form-label">乘客选择</label>
                        <div class="layui-input-block">
                            <div id="transfer" class="demo-transfer"></div>
                        </div>
                    </div> 
                    
                </div>
                <?php if(Cm::$app->limitPost('/order/index','sendcar')){ ?>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="shiftsave">保存</button>
                    </div>
                </div>
                <?php } ?>
            </form>
        </div>
    </div>
</script>
<script type="text/html" id="tpl-shift">
    <select lay-filter="shift" id="shift">
        <option value="">请选择</option>
        {{each shift as item}}
        <option value="{{item.shift_id}}">{{item.departuretime}}</option>
        {{/each}}
    </select>  
</script>
<script type="text/html" id="tpl-car">
    <select lay-filter="car" id="car">
        <option value="">请选择</option>
        {{each car as item}}
        <option value="{{item.id}}" p_seat="{{item.p_seat}}">{{item.plate}}</option>
        {{/each}}
    </select>  
</script>
<script type="text/html" id="tpl-inspector">
    <select lay-filter="inspector" id="inspector">
        <option value="">请选择</option>
        {{each inspector as item}}
        <option value="{{item.id}}" {{init==item.id?'selected=""':''}}>{{item.name}}</option>
        {{/each}}
    </select>  
</script>
<script type="text/html" id="tpl-order-info">
    <div class="layui-card-body">
        <div class="layui-row">
            <label class="layui-form-label">线路名称：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{item.info.circuitname}}</div>
            </div>
        </div> 
        <div class="layui-row">
            <label class="layui-form-label">城市行程：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{item.info.citysname}}--{{item.info.cityename}}</div>
            </div>
        </div>    
        <div class="layui-row">
            <label class="layui-form-label">站点行程：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{item.info.sitesname}}--{{item.info.siteename}}</div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">班次类型：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.shifttype==1?'固定班次':'流水班次'}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6">
                <label class="layui-form-label">发车时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.departuretime}}</div>
                </div>
            </div>    
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">下单人：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.name}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">手机号：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.user_telephone}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">订单状态：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">
                        {{if item.info.order_status==0}}
                        <span>待支付</span>
                        {{else if item.info.order_status==1}}
                        <span class="green">已支付待派车</span>
                        {{else if item.info.order_status==2}}
                        <span class="green">已支付已派车</span>
                        {{else if item.info.order_status==3}}
                        <span class="green">已发车</span>
                        {{else if item.info.order_status==4}}
                        <span class="blue">已完成</span>
                        {{else}}
                        <span class="red">已失效</span>
                        {{/if}}
                    </div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">变更状态：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">
                        {{if item.info.status==0}}
                        <span class="red">已取消</span>
                        {{else if item.info.status==3}}
                        <span class="red">已改签</span>
                        {{else if item.info.status==4}}
                        <span class="red">已退款</span>
                        {{else if item.info.status==1}}
                        <span>正常</span>
                        {{else}}
                        <span class="red">已删除</span>
                        {{/if}}
                    </div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">订单号：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.order_number}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">订单总额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.info.order_price}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">订单金额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.info.price}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">服务总额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.info.service_charge}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">保险总额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.info.premium}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">下单来源：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.source==1?'微信':''}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">是否检票：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.is_check==0?'否':'是'}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">下单时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.addtime}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">更新时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.updatetime}}</div>
                </div>    
            </div>
        </div>
        <div class="layui-row {{item.info.status==0?'':'hide'}}">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">取消时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.canceltime}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row {{item.info.pay_type==0?'hide':''}}">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">支付方式：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.pay_type==1?'微信':'支付宝'}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">支付时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.info.pay_time}}</div>
                </div>    
            </div>
        </div>
        {{if item.car!=''}}
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">车辆信息</label>
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">车牌：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.car.plate}}</div>
                </div>    
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">检票员：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.car.name}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">手机号：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.car.telephone}}</div>
                </div>    
            </div>
        </div>
        {{/if}}
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">乘客信息</label>
            </div>
        </div> 
        {{each item.passenger as vs}}
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">姓名：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{vs.name}}(<span class="{{vs.is_check==0?'':'green'}}">{{vs.is_check==0?"未检票":"已检票"}}</span>)</div>
                </div>    
            </div>
            <div class="layui-col-xs6 {{vs.seat_number !=0 ? '':'hide'}}"> 
                <label class="layui-form-label">车位座：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{vs.seat_number}}号</div>
                </div>    
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">手机：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{vs.telephone}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">身份证：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{vs.id_card}}</div>
                </div>    
            </div>
        </div>
        {{/each}}
    </div>
</script>
<script type="text/html" id="tpl-order-refundinfo">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label" style="width: 100px;">退款单单号：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.refund_number}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">退款金额：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.refund_amount}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">手续费：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">￥{{item.refund_service}}</div>
                </div>    
            </div>
        </div> 
        <div class="layui-row">
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">退款状态：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.refund_status==0?'退款中':(item.refund_status==1?'退款成功':'退款失败')}}</div>
                </div>    
            </div>
            <div class="layui-col-xs6"> 
                <label class="layui-form-label">退款时间：</label>
                <div class="layui-input-inline">
                    <div class="layui-form-mid">{{item.refund_time}}</div>
                </div>    
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="tpl-audit-info">
    <div class="layui-row">
        <label class="layui-form-label">线路名称：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{item.circuitname}}</div>
        </div>
    </div> 
    <div class="layui-row">
        <label class="layui-form-label">城市行程：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{item.citysname}}--{{item.cityename}}</div>
        </div>
    </div>    
    <div class="layui-row">
        <label class="layui-form-label">站点行程：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{item.sitesname}}--{{item.siteename}}</div>
        </div>
    </div>
    <div class="layui-row">
        <label class="layui-form-label">发车时间：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{item.departuretime}}</div>
        </div>
    </div>
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">审核备注：</label>
                <div class="layui-input-block">
                    <textarea name="msg" placeholder="请输入备注" class="layui-textarea"></textarea>
                </div>
            </div>      

            <?php if(Cm::$app->limitPost('/order/index','changesave')){ ?>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="audit_ok">同意</button>
                    <button class="layui-btn layui-btn-danger" lay-submit="" lay-filter="audit_no">拒绝</button>
                    <a class="layui-btn layui-btn-primary" href="javascript:;" onclick="app.change.close()">取消</a>
                </div>
            </div>
            <?php } ?>
        </form>
    </div>
</script>
<script type="text/html" id="tpl-audit-list">
    {{each item as vs is}}
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">旧线路名称：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.oldcircuitname}}</div>
        </div>
    </div> 
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">旧发车时间：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.olddeparturetime}}</div>
        </div>
    </div>    
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">新线路名称：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.newcircuitname}}</div>
        </div>
    </div>
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">新发车时间：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.newdeparturetime}}</div>
        </div>
    </div>
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">审核备注：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.msg}}</div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs6"> 
            <label class="layui-form-label" style="width: 100px;">添加时间：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid">{{vs.addtime}}</div>
            </div>
        </div>
        <div class="layui-col-xs6"> 
            <label class="layui-form-label">审核结果：</label>
            <div class="layui-input-inline">
                <div class="layui-form-mid"><span class="{{vs.change_audit == 1?'green':'red'}}">{{vs.change_audit == 1?'审核通过':'审核拒绝'}}</span></div>
            </div>
        </div>    
    </div>
    {{if vs.change_audit == 1}}
    <div class="layui-row">
        <label class="layui-form-label" style="width: 100px;">改签新订单：</label>
        <div class="layui-input-inline">
            <div class="layui-form-mid">{{vs.auditnumber}}</div>
        </div>
    </div>
    {{/if}}
    {{if is!=0}}
    <div class="xian"></div>
    {{/if}}
    {{/each}}
</script>
<script>
    var app = {
        init:function(){
            $('#data-list').table();
            app.form.init();
        },
        add:function(){
            $.post(baseUrl+'&action=save',{},function (d) {
                if(d.flag)
                {
                    layer.msg(d.msg);
                    $('#data-list').table();
                }else{
                    layer.msg(d.msg);
                }
            },'json')
        },
        form: {
            obj: null,
            init: function () {
                var form = layui.form;
                form.render();
                this.obj = form;
            },
            render: function () {
                this.obj.render();
            }
        },
        transfer:{
            obj: null,
            init: function () {
                layui.config({
                  base: '<?php echo RES_URL?>/res/js/transfer/'
                }).use('transfer', function(){
                    var transfer = layui.transfer;
                    this.obj = transfer;

                    transfer.render({
                        elem: '#transfer'
                        ,title: ['订单', '乘客']  
                        ,data: app.sendcar.list
                        ,id:"passenger"
                        ,parseData: function(res){
                            return {
                              "value": res.order_number //数据值
                              ,"title": res.order_number+"("+res.ridership+"人)" //数据标题
                              ,"ridership":res.ridership
                              ,"passenger":res.passenger
                              ,"order_id":res.order_id
                              , "disabled": ""
                              , "checked": ""
                            }
                        }
                        ,onchange: function(obj, index){
                            var newpassenger = transfer.getData('passenger'); 
                            var p_seat = parseInt(app.sendcar.car_p_seat);
                            var num = 0;
                            $.each(newpassenger,function(index,value){
                                num += parseInt(value.ridership);
                            })
                            var oldarr = [];
                            $.each(app.sendcar.passenger,function(index,value){
                                oldarr.push(value.value);
                            })
                            if(p_seat<num){
                                layer.msg("选择订单的乘客总数已超出所选车辆的乘客数");
                                transfer.reload('passenger', {
                                    data: app.sendcar.list
                                    ,title: ['订单', '乘客']
                                    ,value: oldarr
                                })
                                return false;
                            }else{
                                app.sendcar.passenger = newpassenger
                            }    
                        }
                        ,height: 210
                    })
                });
            }   
        },
        sendcar:{
            circuit:[],
            shift:[],
            car:[],
            inspector:[],
            list:[],
            passenger:[],
            car_p_seat:0,
            passengerarr:[],
            data:{
                circuit_id:0,
                shift_id:0,
                inspector:0,
                car_id:0,
                passenger:'',
                order:''
            },
            hascheck:function(){
                $.post(baseUrl+'&action=sendcar',{ischeck:1},function (d) {
                    if(d.flag){
                        app.sendcar.circuit = d.data;
                        var ly_dtxm = layer.open({
                            title:false,
                            area:['90%','80%'],
                            type:1,
                            content:template('tpl-sendcar', {circuit:d.data}),
                            success: function(layero, index){
                                var height = $("#layui-layer" + index).height() - 150;
                                $("#layui-layer" + index +" form #sendcar-box").css("height",height+"px")
                                app.form.obj.on('select(circuit)',function(data){
                                    app.sendcar.data.circuit_id = data.value;
                                    app.sendcar.data.shift_id = 0;
                                    app.sendcar.data.car_id = 0;
                                    app.sendcar.data.passenger = '';
                                    app.sendcar.passenger =[];
                                    app.sendcar.passengerarr =[];
                                    app.sendcar.shift = app.sendcar.circuit[data.value].shift;

                                    $("#shift-box").html(template("tpl-shift",{shift:app.sendcar.shift}))
                                    $(".passenger-box").hide();
                                    $("#transfer").html("");
                                    app.form.render();
                                });
                                app.form.obj.on('select(shift)',function(data){
                                    app.sendcar.data.shift_id = data.value;
                                    app.sendcar.data.car_id = 0;
                                    app.sendcar.data.passenger = '';
                                    app.sendcar.passenger =[];
                                    app.sendcar.passengerarr =[];
                                    app.sendcar.getpassenger(data.value);
                                    $(".passenger-box").hide();
                                    $("#transfer").html("");
                                });
                                app.form.obj.on('select(inspector)',function(data){
                                    app.sendcar.data.inspector = data.value;
                                });
                                app.form.obj.on('select(car)',function(data){
                                    app.sendcar.data.car_id = data.value;
                                    app.sendcar.car_p_seat = $("#car option[value='"+data.value+"']").attr("p_seat");
                                    app.sendcar.passenger =[];
                                    app.sendcar.passengerarr =[];
                                    if(data.value!=''){
                                        $(".passenger-box").show();
                                        app.transfer.init();
                                    }else{
                                        $(".passenger-box").hide();
                                        $("#transfer").html("");
                                    }
                                });
                                app.form.obj.on('submit(shiftsave)',function(data){
                                    var i = 1;
                                    app.sendcar.passengerarr = [];
                                    var orderarr = [];
                                    $.each(app.sendcar.passenger,function(index,value){
                                        var passenger = value.passenger;
                                        orderarr.push(value.order_id);
                                        $.each(value.passenger,function(is,vs){
                                            var arr = {
                                                passenger_id:vs.passenger_id,
                                                seat_number:i,
                                                order_id:value.order_id
                                            }
                                            i++;
                                            app.sendcar.passengerarr.push(arr)
                                        });
                                    });
                                    if(app.sendcar.data.car_id == 0){
                                        layer.msg("请选择车辆!", {icon: 5});
                                        return false;
                                    }
                                    if(app.sendcar.data.circuit_id == 0){
                                        layer.msg("请选择路线!", {icon: 5});
                                        return false;
                                    }
                                    if(app.sendcar.data.inspector == 0){
                                        layer.msg("请选择检票工作人员!", {icon: 5});
                                        return false;
                                    }
                                    if(app.sendcar.data.shift_id == 0){
                                        layer.msg("请选择班次!", {icon: 5});
                                        return false;
                                    }
                                    if(app.sendcar.passengerarr.length == 0){
                                        layer.msg("请选择乘客!", {icon: 5});
                                        return false;
                                    }
                                    app.sendcar.data.passenger = JSON.stringify(app.sendcar.passengerarr);
                                    app.sendcar.data.order = JSON.stringify(orderarr);
                                    app.sendcar.save();
                                    return false;
                                });
                            }
                        });
                        app.form.render();
                    }else{
                        layer.msg(d.msg);
                    }
                },'json');
            },
            getpassenger:function(id){
                $.post(baseUrl+'&action=sendcar',{isorderlist:1,id:id},function (d) {
                    if(d.flag){
                        app.sendcar.car = d.data.car;
                        app.sendcar.inspector = d.data.inspector;
                        app.sendcar.list = d.data.list;
                        var shift = app.sendcar.shift[id];
                        $("#car-box").html(template("tpl-car",{car:app.sendcar.car}))
                        if(shift.inspector!=0){
                            app.sendcar.data.inspector = shift.inspector;
                        }
                        $("#inspector-box").html(template("tpl-inspector",{inspector:app.sendcar.inspector,init:shift.inspector}));
                        app.form.render();
                    }else{
                        layer.msg("获取数据失败")
                    }
                },'json');
            },
            save:function(){
                $.post(baseUrl+'&action=save',app.sendcar.data,function (d) {
                    if(d.flag)
                    {
                        layer.closeAll();
                        layer.msg(d.msg);
                        $('#data-list').table();
                    }else{
                        layer.msg(d.msg);
                    }
                },'json')
            }
        },
        info:function(e,id){
            $.post(baseUrl+'&action=info',{id:id},function (d) {
                if(d.flag)
                {
                    layer.open({
                        title:'订单详情',
                        area:['600px','60%'],
                        type:1,
                        shadeClose:true,
                        content:template('tpl-order-info', {item:d.data})
                    });
                }else{
                    layer.msg(d.msg);
                }
            },'json')
        },
        refundinfo:function(e,id){
            var str=$(e).parent().find('span').html();
            var json=eval('('+str+')');
            layer.open({
                title:'退票详情',
                area:['600px','300px'],
                type:1,
                shadeClose:true,
                content:template('tpl-order-refundinfo', {item:json})
            });
        },
        change:{
            audit:function(e,id){
                $.post(baseUrl+'&action=auditinfo',{id:id},function (d) {
                    if(d.flag)
                    {
                        layer.open({
                            title:'改签审核',
                            area:['600px','400px'],
                            type:1,
                            content:template('tpl-audit-info', {item:d.data})
                        });
                        app.form.obj.on('submit(audit_ok)', function (data) {
                            var msg = data.field.msg;
                            app.change.save(msg,1,id);
                            return false;
                        });
                        app.form.obj.on('submit(audit_no)', function (data) {
                            var msg = data.field.msg;
                            app.change.save(msg,2,id);
                            return false;
                        });
                    }else{
                        layer.msg(d.msg);
                    }
                },'json')
            },
            save:function(msg,change_audit,id){
                $.post(baseUrl+'&action=changesave',{id:id,msg:msg,change_audit:change_audit},function (d) {
                    layer.msg(d.msg);
                    if(d.flag)
                    {
                        layer.closeAll();
                        $('#data-list').table();        
                    }
                },'json')
            },
            close:function(){
                layer.closeAll();
                return false;
            },
            list:function(e,id){
                $.post(baseUrl+'&action=changelist',{id:id},function (d) {
                    if(d.flag)
                    {
                        layer.open({
                            title:'改签审核',
                            area:['600px','60%'],
                            type:1,
                            shadeClose:true,
                            content:template('tpl-audit-list', {item:d.data})
                        });       
                    }else{
                        layer.msg(d.msg);
                    }
                },'json')
            }
        }
    };

    app.init();
</script>